linux下安装mysql的方法 您所在的位置:网站首页 red hat linux系统命令 linux下安装mysql的方法

linux下安装mysql的方法

2024-07-01 04:51| 来源: 网络整理| 查看: 265

安装Mysql 参考地址: https://blog.csdn.net/zhoudatianchai/article/details/87883688 下载linux对应的版本: 这里Linux 是 Red Hat 6.8,所以下载了 :Red Hat Enterprise Linux 6 / Oracle Linux 6 (x86, 64-bit), RPM Bundle, 包名: (mysql-5.7.34-1.el6.x86_64.rpm-bundle.tar) 下载地址: https://dev.mysql.com/downloads/mysql/ 这里使用的是rpm包安装,下载对应的社区版rpm包 ,不能只下载mysql-server服务器,因为有依赖关系,得至少下载下面五个包

1 将windows下的文件拷贝到 Linux虚拟机

[root@Master software]# cp /mnt/hgfs/H/install_src/app_linux/mysql-5.7.34-1.el6.x86_64.rpm-bundle.tar /usr/local/software/install_src/

2 解压到指定目录

[root@Master software]# tar -xvf /usr/local/software/install_src/mysql-5.7.34-1.el6.x86_64.rpm-bundle.tar -C /usr/local/software/install_src/

3 查看已安装 的mysql包

[root@Master install_src]# rpm -qa|grep mysql mysql-libs-5.1.73-7.el6.x86_64 [root@Master install_src]# service mysqld start mysqld: unrecognized service

##查看解压文件:

[root@Master mysql]# ls -l total 963544 -rwxr-xr-x. 1 root root 493332480 Aug 5 12:14 mysql-5.7.34-1.el6.x86_64.rpm-bundle.tar -rw-r--r--. 1 7155 31415 26022228 Mar 27 00:49 mysql-community-client-5.7.34-1.el6.x86_64.rpm -rw-r--r--. 1 7155 31415 377844 Mar 27 00:49 mysql-community-common-5.7.34-1.el6.x86_64.rpm -rw-r--r--. 1 7155 31415 4087492 Mar 27 00:49 mysql-community-devel-5.7.34-1.el6.x86_64.rpm -rw-r--r--. 1 7155 31415 39578388 Mar 27 00:49 mysql-community-embedded-5.7.34-1.el6.x86_64.rpm -rw-r--r--. 1 7155 31415 138439076 Mar 27 00:49 mysql-community-embedded-devel-5.7.34-1.el6.x86_64.rpm -rw-r--r--. 1 7155 31415 2530056 Mar 27 00:49 mysql-community-libs-5.7.34-1.el6.x86_64.rpm -rw-r--r--. 1 7155 31415 1760740 Mar 27 00:49 mysql-community-libs-compat-5.7.34-1.el6.x86_64.rpm -rw-r--r--. 1 7155 31415 169746568 Mar 27 00:49 mysql-community-server-5.7.34-1.el6.x86_64.rpm -rw-r--r--. 1 7155 31415 110776084 Mar 27 00:50 mysql-community-test-5.7.34-1.el6.x86_64.rpm

将搜索出的包名卸载: #rpm -e –nodeps mysql-libs-5.1.73-7.el6.x86_64 (nodeps表示强制删除) 希望删除,但是存在依赖无法删除; 再看mysql 路径

[root@Master install_src]# rpm -e mysql-libs-5.1.73-7.el6.x86_64 error: Failed dependencies: libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64 libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64 mysql-libs is needed by (installed) postfix-2:2.6.6-6.el6_7.1.x86_64 [root@Master install_src]# which mysql /usr/bin/which: no mysql in (/usr/local/software/jdk1.8.0_191/bin:/usr/local/software/spark-2.3.2-bin-hadoop2.7/bin:/usr/local/software/scala-2.11.12/bin:/usr/local/software/hadoop-2.7.7/bin:/home/dhy/anaconda3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin)

4 开始安装mysql数据库啦,注意了官方文档说啦,各个文件是有依赖性的,必须按以下顺序安装,你也可以试试其他顺序,看看提示的错误 安装顺序 mysql-community-common-5.7.18-1.el7.x86_64.rpm mysql-community-libs-5.7.18-1.el7.x86_64.rpm mysql-community-client-5.7.18-1.el7.x86_64.rpm imysql-community-server-5.7.18-1.el7.x86_64.rpm mysql-community-devel-5.7.18-1.el7.x86_64.rpm 安装出错提示 有冲突, conflict (机子上已经安装其它版本的mysql数据库) 具体如下: [root@Master mysql]# rpm -ivh mysql-community-common-5.7.34-1.el6.x86_64.rpm 运行出错情况:

[root@Master mysql]# rpm -ivh mysql-community-common-5.7.34-1.el6.x86_64.rpm warning: mysql-community-common-5.7.34-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ########################################### [100%] file /usr/share/mysql/czech/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/danish/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/dutch/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/english/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/estonian/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/french/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/german/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/greek/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/hungarian/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/italian/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/japanese/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/korean/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/norwegian-ny/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/norwegian/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/polish/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/portuguese/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/romanian/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/russian/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/serbian/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/slovak/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/spanish/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/swedish/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/ukrainian/errmsg.sys from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/Index.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/armscii8.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/ascii.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/cp1250.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/cp1251.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/cp1256.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/cp1257.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/cp850.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/cp852.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/cp866.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/dec8.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/geostd8.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/greek.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/hebrew.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/hp8.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/keybcs2.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/koi8r.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/koi8u.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/latin1.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/latin2.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/latin5.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/latin7.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/macce.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/macroman.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.34-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-7.el6.x86_64 [root@Master mysql]#

出现了冲突,也就是安装失败, 安装后面的libs 出现无法安装的提示。

[root@Master mysql]# rpm -ivh mysql-community-libs-5.7.34-1.el6.x86_64.rpm warning: mysql-community-libs-5.7.34-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: mysql-community-common(x86-64) >= 5.7.9 is needed by mysql-community-libs-5.7.34-1.el6.x86_64

需要删除已经安装的旧版本,采用yum -y remove命令删除

[root@Master mysql]# yum -y remove mysql-libs-5.1.73*

再执行以下命令安装MySQL: 次序为:common、 libs、client、 server、devel rpm -ivh mysql-community-common-5.7.34-1.el6.x86_64.rpm rpm -ivh mysql-community-libs-5.7.34-1.el6.x86_64.rpm rpm -ivh mysql-community-client-5.7.34-1.el6.x86_64.rpm rpm -ivh mysql-community-server-5.7.34-1.el6.x86_64.rpm rpm -ivh mysql-community-devel-5.7.34-1.el6.x86_64.rpm

[root@Master mysql]# rpm -ivh mysql-community-common-5.7.34-1.el6.x86_64.rpm warning: mysql-community-common-5.7.34-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ########################################### [100%] 1:mysql-community-common ########################################### [100%] [root@Master mysql]# rpm -ivh mysql-community-libs-5.7.34-1.el6.x86_64.rpm warning: mysql-community-libs-5.7.34-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ########################################### [100%] 1:mysql-community-libs ########################################### [100%] [root@Master mysql]# rpm -ivh mysql-community-client-5.7.34-1.el6.x86_64.rpm warning: mysql-community-client-5.7.34-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ########################################### [100%] 1:mysql-community-client ########################################### [100%] [root@Master mysql]# rpm -ivh mysql-community-server-5.7.34-1.el6.x86_64.rpm warning: mysql-community-server-5.7.34-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ########################################### [100%] 1:mysql-community-server ########################################### [100%] [root@Master mysql]# rpm -ivh mysql-community-devel-5.7.34-1.el6.x86_64.rpm warning: mysql-community-devel-5.7.34-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ########################################### [100%] 1:mysql-community-devel ########################################### [100%] [root@Master mysql]#

官方安装说明地址: https://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html 5 安装完成后,启动mysql 。采用service mysqld start 命令 ##出现启动失败: [root@Master mysql]# service mysqld start Initializing MySQL database: [FAILED] ##更换到root权限下执行 [root@Master mysql]# sudo service mysqld start Starting mysqld: [ OK ]

6 启动之后密码就初始化好了, vim /var/log/mysqld.log 查看 ps 是 mysqld.log 不是mysql.log

2021-08-05T06:54:40.633731Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-08-05T06:54:40.845319Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-08-05T06:54:40.879220Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-08-05T06:54:40.944536Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 01e5175a-f5ba-11eb-b7d6-000c29f0b4d3. 2021-08-05T06:54:40.946723Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-08-05T06:54:41.820143Z 0 [Warning] CA certificate ca.pem is self signed. 2021-08-05T06:54:41.899831Z 1 [Note] A temporary password is generated for root@localhost: ;hlv)vg9qIwV 2021-08-05T06:54:43.214632Z 1 [ERROR] Failed to open the bootstrap file /var/lib/mysql-files/install-validate-password-plugin.iCpLlF.sql 2021-08-05T06:54:43.214648Z 1 [ERROR] 1105 Bootstrap file error, return code (0). Nearest query: 'SET @@sql_log_bin = @sql_log_bin;

7 登录MySQL,登录进去是没有权限任何操作的,必须修改密码 输入上一步查看到的临时密码,我这里是 ;hlv)vg9qIwV 先mysql -uroot -p 输入密码登陆,并用SET password 执行修改密码语句。 修改密码在mysql下采用代码, set password for ‘root’@‘localhost’=‘newpasswd’ newpasswd就是设置的新密码,密码必须要符合要求,八位及以上,需要大小写、数字和特殊字符。

[root@Master mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.34 Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> set password for 'root'@'localhost'='Dhy_123'; Query OK, 0 rows affected (0.00 sec) mysql> exit

8修改MySQL的登录设置的方法 1修改MySQL的登录设置: # vi /etc/my.cnf 在[mysqld]的段中加上一句:skip-grant-tables ##跳过权限验证 在[mysqld]的段中加上一句:skip-name-resolve ##跳过域名解析

例如: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock skip-name-resolve

2、重新启动mysqld

service mysqld restart

3、将MySQL的登录设置修改回来

vi /etc/my.cnf

将刚才在[mysqld]的段中加上的skip-grant-tables删除

保存并且退出vi。

4、重新启动mysqld [root@Master mysql]# service mysqld restart Stopping mysqld: [ OK ] Starting mysqld: [ OK ] [root@Master mysql]# 5、创建新用户 grant all privileges on . to root@’%’ identified by ‘123456’;

9 到此就算mysql数据库安装完成了,接下来就是漫长的mysql学习之路,祝你成功!

mysql5.7初始化密码报错 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before

#首先,修改validate_password_policy参数的值

mysql> set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec)

validate_password_length(密码长度)参数默认为8,我们修改为1

mysql> set global validate_password_length=1; Query OK, 0 rows affected (0.00 sec)

#完成之后再次执行修改密码语句即可成功

mysql> alter user ‘root’@‘localhost’ identified by ‘123456’; Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges ; Query OK, 0 rows affected (0.01 sec)

10 将mysqld服务加入开机自启动项。 先检查下mysql是否在自启动列表: chkconfig --list mysqld [root@Master usr]# chkconfig --list|grep mysql mysqld 0:off 1:off 2:off 3:on 4:on 5:on 6:off

将mysql加入自启动列表: chkconfig --level 345 mysqld on 重启验证: 执行reboot指令。等到服务器重启好了。我们来验证mysql是否启动成功。 验证的方法有很多 service mysqld status ps aux | grep mysql 或者干脆直接登录mysql mysql -uroot



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有